import java.util.Scanner;

public class Arrays_neighbouring_numbers {

	public static void main(String[] args) {
		
		int sizeOfArray = 0;	
		Scanner inputUserData = new Scanner(System.in);
		System.out.println("Enter the array's size: ");
		if(inputUserData.hasNextInt()){
			sizeOfArray = inputUserData.nextInt();		
		}
		int array[] = new int[sizeOfArray];
		System.out.println("Enter the array's numbers: ");
		if(inputUserData.hasNextInt()){
			for(int index = 0; index < array.length ; index++){
					array[index] = inputUserData.nextInt();
					System.out.println("# "+index+ " = "+array[index]+", ");
			}				
		}
		int FirstNeighbouringNumber = 0;
		int SecondNeighbouringNumber = 0;
		int IndexOfFirstNumber = 0;
		
		for(int index = 2; index < array.length ; index++){			
			if( array[index-2] == array[index-1]){
				FirstNeighbouringNumber = array[index-2];
				SecondNeighbouringNumber = array[index-1];
				IndexOfFirstNumber = index-2;	
				break;
			}else if(array[index-1] == array[index]){
				FirstNeighbouringNumber = array[index-1];
				SecondNeighbouringNumber = array[index];
				IndexOfFirstNumber = index-1;	
				break;
			}					
			else if( Math.abs((array[index-2])-(array[index-1])) < Math.abs((array[index-1])-(array[index])) ){
				FirstNeighbouringNumber = array[index-2];
				SecondNeighbouringNumber = array[index-1];
				IndexOfFirstNumber = index-2;
				}
			else if( Math.abs((array[index-2])-(array[index-1])) > Math.abs((array[index-1])-(array[index])) ){
				FirstNeighbouringNumber = array[index-1];
				SecondNeighbouringNumber = array[index];
				IndexOfFirstNumber = index-1;	
				}
			else if( Math.abs((array[index-2])-(array[index-1])) == Math.abs((array[index-1])-(array[index])) ){
				FirstNeighbouringNumber = array[index-2];
				SecondNeighbouringNumber = array[index-1];
				IndexOfFirstNumber = index-2;	
				}
		}
		System.out.println(" The minimal distance is between "+FirstNeighbouringNumber+ " and "+SecondNeighbouringNumber);
		System.out.println(" The index of the first number in the distance is "+IndexOfFirstNumber);

	}}


